/**
 * 候选人窄列表
 */
import React from 'react';
import { Table } from 'antd';
import { TableFilter } from '@/components';
import { getDisplayText, getDict } from '@/utils/dataDictUtil';
import {
    renderPhone,
    renderShortDate,
    renderCandidateStatus,
    renderNameWithReadFlagTitle,
    renderNameWithReadFlag,
    renderCandidateRecordOperate,
    renderTalentDegree,
    renderLastPost
} from '../renderUtil';
import { CANDIDATE_STATUS, SEX, LAST_POST_STATUS } from '../dictionary';

const CandidateCommonTable = ({
    loading,
    dataSource,
    condition,
    onJumpDetail,
    onRefresh,
    sortOrders,
    isPrincipal,
    isLauncher,
    channelDict,
    ...rest
}) => {
    const [agreeTypeList, setAgreeTypeList] = React.useState([]); // 学历

    // 字典获取
    React.useEffect(() => {
        getDict('agreeType').then(ret => setAgreeTypeList(ret));
    }, []);

    // const handleChange = (id, res) => {
    //     if (onRowChange) {
    //         onRowChange(id, res);
    //     }
    // };

    const columns = [
        {
            title: renderNameWithReadFlagTitle('姓名'),
            dataIndex: 'readFlag',
            render: (value, record) => {
                const { talentName = '--', showReadFlag, hasBlackList } = record;
                return renderNameWithReadFlag(talentName, value, showReadFlag, hasBlackList);
            }
        },
        {
            title: '性别',
            dataIndex: 'talentSex',
            width: 80,
            filteredValue: condition.talentSex ? [condition.talentSex] : [],
            filters: SEX,
            filterMultiple: false,
            filterDropdown: filterProps => <TableFilter {...filterProps} />,
            render: sex => getDisplayText(SEX, sex)
        },
        {
            title: '手机',
            dataIndex: 'talentPhone',
            render: renderPhone
        },
        {
            title: '学历',
            dataIndex: 'talentDegree',
            width: 100,
            filteredValue: condition.talentDegree ? [condition.talentDegree] : [],
            filters: agreeTypeList,
            filterMultiple: false,
            filterDropdown: filterProps => <TableFilter {...filterProps} />,
            render: (val, record) =>
                renderTalentDegree(getDisplayText(agreeTypeList, val), record.talentEduDetailVOList)
        },
        {
            title: '最近工作',
            dataIndex: 'lastPost',
            render: (val, record) => renderLastPost(val, record.talentWorkDetailVOList)
        },
        {
            title: '在职情况',
            dataIndex: 'lastPostStatus',
            filteredValue: condition.lastPostStatus ? [condition.lastPostStatus] : [],
            filters: LAST_POST_STATUS,
            filterMultiple: false,
            filterDropdown: filterProps => <TableFilter {...filterProps} />,
            render: val => getDisplayText(LAST_POST_STATUS, val)
        },
        {
            title: '渠道',
            dataIndex: 'notesSource',
            filteredValue: condition.notesSource ? [condition.notesSource] : [],
            filters: channelDict,
            filterMultiple: false,
            filterDropdown: filterProps => <TableFilter {...filterProps} />,
            render: val => getDisplayText(channelDict, val)
        },
        {
            title: '推荐时间',
            dataIndex: 'recommendTime',
            sortOrder: sortOrders?.recommendTime || false,
            render: val => renderShortDate(val, 'MM-DD HH:mm')
        },
        {
            title: '状态',
            dataIndex: 'candidateStatus',
            width: 80,
            filteredValue: condition.candidateStatus ? [condition.candidateStatus] : [],
            filters: CANDIDATE_STATUS,
            filterMultiple: false,
            filterDropdown: filterProps => <TableFilter {...filterProps} />,
            render: (val, record) => renderCandidateStatus(val, record.candidateStatusHover)
        },
        {
            title: '操作',
            dataIndex: 'action',
            width: 150,
            onCell: () => ({
                onClick: e => {
                    e.stopPropagation();
                }
            }),
            render: (_, record) => renderCandidateRecordOperate(record, onRefresh, isPrincipal, isLauncher)
        }
    ];
    return (
        <>
            <Table
                {...rest}
                rowKey="id"
                bordered={false}
                columns={columns}
                loading={loading}
                dataSource={dataSource}
                pagination={false}
                onRow={record => ({
                    onClick: () => {
                        const { recruitTalentMatcherId, id } = record;
                        if (onJumpDetail) onJumpDetail(id, recruitTalentMatcherId, record);
                    }
                })}
            />
        </>
    );
};
export default CandidateCommonTable;
